package com.sanrenzu.everybodytv.ui.recommend.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.sanrenzu.everybodytv.R;
import com.sanrenzu.everybodytv.bean.sms.BannerBean;
import com.sanrenzu.everybodytv.ui.recommend_live.VideoViewActivity;

import java.util.List;

/**
 * Created by asus on 2016/9/6.
 */
public class ViewPagerAdapter extends PagerAdapter {

    private List<BannerBean> list ;
    private Context mContext;
    private LayoutInflater mInflater;

    public ViewPagerAdapter(Context mContext, List<BannerBean> list){
        this.mContext = mContext;
        this.list = list;
        mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        View view = mInflater.inflate(R.layout.viewpager_item,container,false);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(mContext,"ViewPager点击了",Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(mContext, VideoViewActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("url",list.get(position).getLink_object().getUid());
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });
        ImageView imageView = (ImageView) view.findViewById(R.id.imageView_item_ViewPager_thumb);
        Glide.with(mContext).load(list.get(position).getThumb()).into(imageView);
        TextView textView = (TextView) view.findViewById(R.id.textView_item_viewPager_title);
        textView.setText(list.get(position).getTitle());
        container.addView(view);

        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
